package org.example.platform.design.simplefactory.version2.book.version1;


import org.example.platform.design.simplefactory.version2.Futil;
import org.example.platform.design.simplefactory.version2.me.MethodServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 简单工厂   第2版
 */
public class Factory {

    @Autowired
    MethodServiceImpl methodServiceImpl;

    /**
     * 第2版
     * 输入两个数字，一个运算符，得出结果
     * 使用继承和多态
     *
     * @param option
     */
    public  static void inputNum2(Option option) throws Exception {
        try {
            Futil.isNumNotNull(option.getNum());
            Futil.isNum2NotNull(option.getNum2());
            Futil.isFhNotNull(option.getFh());
        } catch (Exception e) {
            throw new Exception(e.getMessage());
        }
        double result = 0.00;
        switch (option.getFh()) {
            case "*":
                result = new MultVo().getResult();
                break;
            case "-":
                result = new ReduceVo().getResult();
                break;
            case "/":
                result = new ExceptVo().getResult();
                break;
            case "+":
                result = new AddVo().getResult();
                break;
            case "^":
                result = new AddVo().getResult();
                break;
        }
        System.out.println(result);
    }

    public static void main(String[] args) throws Exception {
        Option result = new Option();
        result.setFh("*");
        result.setNum(6);
        result.setNum2(7);
        inputNum2(result);
        System.out.println(result);
    }
}
